/**
 * Created by lixiaodi on 2018/10/24.
 */
mini.parse();
//得到需要操作的控件赋值给变量
var reportGrid  = mini.get("reportGrid");
var reporParam;
//按钮控件
var addBtn = mini.get("addBtn");
var editBtn = mini.get("editBtn");
var removeBtn = mini.get("removeBtn");
/*var saveBtn = mini.get("saveBtn");*/
//配置信息
var configure = {
    alertUrl  : bootPATH + "../frame/frame1/pages/reportForm/searchBase.html",        //弹出窗口路径
    addTitle  : "查询条件",                 //增加窗口标题
    editTitle : "编辑菜单",                 //编辑窗口标题
    obj       : reportGrid                //被点击的对象
}
//增删改对象
var Handle = {
    //增加
    add : function(){
       console.log(reporParam);
        mini.open({
            url     : configure.alertUrl,
            title   : configure.addTitle,
            width   : 600,
            height  : 500,
            onload  : function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "new",
                    reportId: reporParam
                };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                console.log(action,"action");
                    ajaxBack(reporParam);
             
            }
        })
    },
    //编辑(修改)
    edit : function(){
        //得到当前选中行（需编辑的行）
        var row = reportGrid.getSelected();
        if(row){
            mini.open({
                url     : configure.alertUrl,
                title   : configure.editTitle,
                width   : 600,
                height  : 400,
                onload  : function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        action: "edit",
                        reportId: reporParam,
                        id: row.seachId
                    };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    ajaxBack(reporParam);
                }
            });
        }
    },
    //保存
    save : function(){
        var colums = [];        //条件数组
        var stringStr;
        var row = reportGrid.getSelected();
        //for(var key in row){
        //    stringStr = "and " + key + "=" + key;
        //    colums.push(stringStr);
        //}
    },
    //删除
    remove : function(){
        var row = reportGrid.getSelected();
        if(row){
            mini.confirm("确定删除选中记录？","系统提示",function(action){
                if (action == "ok"){
                    var id = row.seachId;
                    reportGrid.loading("操作中，请稍后......");
                    $.ajax({
                        url: ajaxUrl + "/seachParamController/deleteSerchParam.do?id=" + id,
                        type:"POST",
                        success: function (text) {
                            console.log(text);
                            ajaxBack();
                        },
                        error: function () {
                            mini.alert('失败');
                        }
                    });
                }
            })
        }
    }
}
//点击事件(增删改查)
addBtn.on("click",Handle.add);
editBtn.on("click",Handle.edit);
removeBtn.on("click",Handle.remove);
/*saveBtn.on("click",Handle.save);*/
//编辑
function SetData(data){
    data = mini.clone(data);
    reporParam = data.reportId;
    if(data.action == "new"){
        ajaxBack(reporParam);
    }
}
function ajaxBack(){
    $.ajax({
        url : ajaxUrl + "/seachParamController/FindSerchlist.do?reportId=" + reporParam,
        type : "POST",
        success : function(data){
            reportGrid.setData(data.data);
        }
    });
}